<?php /*
	*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}
// IF admin is not logged in then it will redirect to the adminlogin page.
if(!isset($_SESSION['adminuserid']))
{
	header("location:adminlogin.php?msg=logfirst");
	die();
}

// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")
	{
				
				$taxtcountry = $_REQUEST['currtitle'];
				$taxtisocode2 = $_REQUEST['currcode'];
				$taxtisocode3 = $_REQUEST['symleft'];
				$taxtisocode4 = $_REQUEST['symright'];
				$taxtisocode5 = $_REQUEST['currvalues'];
				
				$insert = "INSERT INTO `tblcurrencies`
				(`vartitle` , `varcurrcode` , `varsymbolleft`, `varsymbolright` , `decvalues`)
				VALUES ('$taxtcountry', '$taxtisocode2', '$taxtisocode3', '$taxtisocode4', '$taxtisocode5')";
				
				$sql=$obj_db->insert($insert);
				
				
				
				header("location:currency.php?msg=add");
				die();
	}	
		

// UPDATE the record
$txtcountry1 = "";
$txtisocode21 = "";
$txtisocode31 = "";
$txtisocode41 = "";
$txtisocode51 = "";

$action=1;

if((isset($_REQUEST['a']) && trim($_REQUEST['a'])==2) && (!(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")))
{
 	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid'])!="")
 	{
		$screen_id =  $_REQUEST['intid'];
		$sql = "select * from tblcurrencies where intid ='$screen_id'";
		$result = $obj_db->select($sql);
		
		if(count($result)<=0)
		{
			echo " No Record Found!<br>";
			die();
		}
		
		if($result)
		{
			foreach($result as $row)
			{
				$txtcountry1 = $row['vartitle'];	   
		   		$txtisocode21 = $row['varcurrcode'];
				$txtisocode31 = $row['varsymbolleft'];
				$txtisocode41 = $row['varsymbolright'];
				$txtisocode51 = $row['decvalues'];
				
				
				$action=2;
			}
		}
		
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Update")
		{
				$txtcountry = $_REQUEST['currtitle'];
				$txtisocode2 = $_REQUEST['currcode'];
				$txtisocode3 = $_REQUEST['symleft'];
				$txtisocode4 = $_REQUEST['symright'];
				$txtisocode5 = $_REQUEST['currvalues'];
			
			$sql_upd ="UPDATE tblcurrencies SET  
						`vartitle` = '$txtcountry',
						`varcurrcode` = '$txtisocode2',						 
						`varsymbolleft` = '$txtisocode3',
						`varsymbolright` = '$txtisocode4',						 
						`decvalues` = '$txtisocode5'
						where intid ='$screen_id'";
						 
			//echo $sql_upd;
			//die();
			
			$result = $obj_db->edit($sql_upd);
			$action=1;
			
			header("location:currency.php?msg=edit");
			die();
		}
	}

}

//DELETE record from database
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{	
		$id =  $_REQUEST['intid'];
		$sql= "DELETE FROM `tblcurrencies` WHERE `intid` ='$id'";
		$query1 = mysql_query($sql);
		
		header("location:currency.php?msg=del");
		die();
	}
}

?>
<?php include("inc/header.php");?>
<body>
<script language="javascript" src="js/currency.js"></script>

<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="95%"><?php   
   if(isset($_REQUEST['script']))
	{
	if(trim($_REQUEST['script'])=='addcurrency' || trim($_REQUEST['script'])=='editcurrency')
	{
	?>
		<form action="" method="post" enctype="multipart/form-data" name="currency">
	
      <table width="60%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
        <tr class="bg1">
          <td colspan="5" align="center"><strong>
            <?php if($_REQUEST['script']=='addcurrency'){echo "Add New Currency...";}
	if($_REQUEST['script']=='editcurrency'){echo "Edit Currency...";}?>
          </strong></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left">&nbsp;</td>
          <td>&nbsp;</td>
          <td align="right">(* All fields are Required)</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="2%">&nbsp;</td>
          <td width="30%" align="right" class="sltimg">*Currency Title </td>
          <td width="3%">:</td>
          <td width="56%" align="left"><label>
            <input name="currtitle" type="text" id="currtitle" value="<?php echo $txtcountry1;?>" />
          </label></td>
          <td width="9%">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Currency Code </td>
          <td>:</td>
          <td align="left"><input name="currcode" type="text" id="currcode" value="<?php echo $txtisocode21;?>" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Symbol Left </td>
          <td>:</td>
          <td align="left"><input name="symleft" type="text" id="symleft" value="<?php echo $txtisocode31;?>" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Symbol Right </td>
          <td>:</td>
          <td align="left"><input name="symright" type="text" id="symright" value="<?php echo $txtisocode41;?>" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Values</td>
          <td>:</td>
          <td align="left"><input name="currvalues" type="text" id="currvalues" value="<?php echo $txtisocode51;?>" /></td>
          <td>&nbsp;</td>
        </tr>

        <tr>
          <td colspan="5" align="left">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="5" align="center"><input name="Submit" type="submit" class="btn" id="Submit" value="<?php echo ($action==2) ? "Update":"Submit"; ?>" onClick="return check();"/></td>
        </tr>
        <tr>
          <td colspan="5" align="center">&nbsp;</td>
        </tr>
      </table>
    <?php
	}
}
else
{
?>
<br />
		<br />
		<table width="70%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
          <tr class="bg1">
            <td colspan="6" align="left"><strong >Currency List... </strong>&nbsp;&nbsp;<a href="currency.php?script=addcurrency" class="aa"></a></td>
            <td align="center"><a href="currency.php?script=addcurrency" class="aa">[NEW]</a></td>
          </tr>
          <tr align="center" class="tblbg3">
            <td class="tblbg3">Currency</td>
            <td class="tblbg3">Code</td>
            <td class="tblbg3">Symbol Left</td>
			<td class="tblbg3">Symbol Right</td>
			<td class="tblbg3">Values</td>
			<td class="tblbg3">Edit</td>
            <td>Delete</td>
          </tr>
          <?php
	  
	  
	  
	  /**************************************
		PAGING CODE START
		**************************************/
		//$rowperpage=23;
		$tablename="tblcurrencies";
		$per_page_keywords= "";
		$per_page_sorts="";
		include("system/paging.inc.php");

		/**************************************
		PAGING CODE ENDING
		**************************************/
		?>
          <?php
   		$sql="select * from tblcurrencies Limit ".($page_no*$row_per_page).",".$row_per_page;
		$result=$obj_db->select($sql);
  		if($result)
		{
   		for($i=0;$i<count($result);$i++)
   		{
            $id=$result[$i]['intid'];
			//$imagepath = "../images/manuf/";
			//$limit=$result[$i]['varimagepath'];
			//$imagename = $imagepath.$limit;
			?>
          <tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onMouseOut="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
            <td align="center"><?php echo $result[$i]['vartitle'];?></td>
            <td align="center"><?php echo $result[$i]['varcurrcode'];?></td>
            <td align="center"><?php echo $result[$i]['varsymbolleft'];?></td>
			<td align="center"><?php echo $result[$i]['varsymbolright'];?></td>
			<td align="center"><?php echo $result[$i]['decvalues'];?></td>
			<td align="center"><a class="link" Title="Click here to Edit" href="currency.php?script=editcurrency&amp;a=2&amp;intid=<?php echo $result[$i]['intid']; ?>"><img src="images/edit.bmp" border="0"/></a></td>
            <td align="center"><a Title="Click here to Delete" href="currency.php?a=3&amp;intid=<?php echo $result[$i]['intid']; ?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
          </tr>
          <?php }}?>
          <tr>
            <td colspan="7" align="center"><?php
pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page);
?></td>
          </tr>
        </table>
		<?php }?>
        </form>	</td>
    <td width="3%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><?php include("inc/bottom.php");?></td>
  </tr>
</table>


